<?php
class ErrorHandlerAction extends \Pinenut\Action {

	function run() {
		$this->response->error = $this->request->error;

		if (404 == $this->request->error['code']) {
			header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
		} elseif (404 == $this->request->error['code']) {
			header($_SERVER["SERVER_PROTOCOL"]." 500 Internal server error");			
		}
		
		$trace = $this->request->trace;

		foreach ($trace as &$t) {
			// получаем девять строк из файла
			if (isset($t['file'])) {
				$pos = $t['line'];
				if ($pos > 4) $pos -= 5;
				$file = file($t['file']);
				$file = array_slice($file, $pos, 9);
				foreach ($file as $key=>$val) {
					$t['code'][$key+$pos+1]=rtrim($val);
				}
			}
		}
		$this->response->trace = $trace;
	}
}